<?php
/**
 * 推广链接
 *
 *
 *
 *
 * @copyright  Copyright (c) 2014-2015 TuntronKJ Inc. (http://www.tuntron.com)
 * @license    http://www.tuntron.com
 * @link       http://www.tuntron.com
 * @since      File available since Release v1.1
 */
defined('InTuntronKJ') or exit('Access Invalid!');
class linkModel extends Model {

    public function __construct(){
        parent::__construct('links');
    }


    /**
     * 会员推广链接详情
     * @param unknown $condition
     * @param string $field
     */
    public function getLinkInfo($condition, $field = '*'){
    	return $this->field($field)->where($condition)->find();
    }
    
    /**
     * 会员推广链接列表
     * @param array $condition
     * @param string $field
     * @param number $page
     * @param string $order
     */
    public function getMemberLinks($condition = array(), $field = '*', $page = 0, $limit = 0,$order = 'uid desc') {
       return $this->where($condition)->limit($limit)->page($page)->order($order)->select();
    }
    
    /**
     * 更新推广链接
     * @param unknown $param
     * @param unknown $id
     * @return boolean|Ambigous <boolean, mixed>
     */
    public function updateMemberLinks($param,$id) {
    	if(empty($param)) {
    		return false;
    	}
    	$update		= false;
    	//得到条件语句
    	$condition_str	= " lid='{$id}' ";
    	$update		= Db::update('links',$param,$condition_str);
    	return $update;
    }
    
    /**
     * 添加推广链接
     * @param unknown $param
     * @return boolean|Ambigous <number, unknown>
     */
    public function addMemberLinks($param) {
    	if(empty($param)) {
    		return false;
    	}
    	$result	= Db::insert('links',$param);
    	if($result) {
    		return Db::getLastId();
    	} else {
    		return false;
    	}
    }
    
    /**
     * 删除推广链接
     * @param unknown $id
     * @return Ambigous <boolean, mixed>|boolean
     */
    public function delMemberLinks($id){
    	if (intval($id) > 0){
    		$where = " lid = '". intval($id) ."'";
    		$result = Db::delete('links',$where);
    		return $result;
    	}else {
    		return false;
    	}
    }
}
